<template>
  <el-dialog v-model="visible" title="详情" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataFormRef" label-width="120px">
      <el-form-item prop="teamName" label="参赛代表队">
        {{ dataForm.row.teamName }}
      </el-form-item>
      <el-form-item prop="teamName" label="领队">
        {{ dataForm.row.leader }}
      </el-form-item>
      <el-form-item prop="matchName" label="参与赛事">
        {{ dataForm.row.matchName }}
      </el-form-item>
      <el-form-item prop="item" label="参与赛项">
        {{ dataForm.row.item }}
      </el-form-item>
      <el-form-item prop="dictLabel" label="参赛组别">
        {{ dataForm.row.dictLabel }}
      </el-form-item>
      <el-form-item prop="realName" label="参赛选手">
        {{ dataForm.row.realName }}
      </el-form-item>
      <el-form-item prop="company" label="选手单位">
        {{ dataForm.row.userCompany }}
      </el-form-item>
      <el-form-item prop="groupName" label="参赛队伍">
        {{ dataForm.row.groupName }}
      </el-form-item>
      <el-form-item prop="teacher" label="指导老师">
        {{ dataForm.row.teacher }}
      </el-form-item>
      <el-form-item prop="begin" label="比赛时间">
        {{ dataForm.row.beginDate }}
      </el-form-item>
      <el-form-item prop="signup" label="报名时间">
        {{ dataForm.row.beginSignup }}
      </el-form-item>
      <el-form-item prop="company" label="赛项报名表" v-if="dataForm.row.riseFile">
        <a :href="dataForm.row.riseFile" target="_blank">查看报名表</a>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="visible = false">关闭</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts">
import { defineComponent, reactive } from "vue";
import baseService from "@/service/baseService";
import { isMobile, useDebounce } from "@/utils/utils";
import { IObject } from "@/types/interface";
export default defineComponent({
  setup() {
    return reactive({
      visible: false,
      dataForm: {
        id: "",
        smsCode: "",
        mobile: "",
        params: "",
        row: {
          teamName: "",
          leader: "",
          matchName: "",
          item: "",
          dictLabel: "",
          realName: "",
          userCompany: "",
          groupName: "",
          teacher: "",
          beginDate: "",
          beginSignup: "",
          riseFile: ""
        }
      }
    });
  },
  computed: {
    dataRule() {
      var validateMobile = (rule: IObject, value: string, callback: (e?: Error) => any) => {
        if (!isMobile(value)) {
          return callback(new Error(this.$t("validate.format", { attr: this.$t("user.mobile") })));
        }
        callback();
      };
      return {
        mobile: [
          { required: true, message: this.$t("validate.required"), trigger: "blur" },
          { validator: validateMobile, trigger: "blur" }
        ]
      };
    }
  },
  created() {
    this.dataFormSubmitHandle = useDebounce(this.dataFormSubmitHandle);
  },
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataFormRef"].resetFields();
      });
      console.log(this.dataForm.row);
    },

    // 表单提交
    dataFormSubmitHandle() {
      this.$refs["dataFormRef"].validate((valid: boolean) => {
        if (!valid) {
          return false;
        }
        baseService
          .post("/sys/sms/send", this.dataForm, {
            "content-type": "application/x-www-form-urlencoded"
          })
          .then((res) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg);
            }
            this.$message({
              message: this.$t("prompt.success"),
              type: "success",
              duration: 500,
              onClose: () => {
                this.visible = false;
                this.$emit("refreshDataList");
              }
            });
          });
      });
    }
  }
});
</script>
